﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ch6_label
{
    enum Direction { UP, DOWN, RIGHT,LEFT}
    
    public partial class Form1 : Form
    {

        Direction direction;
        double theta;
        int count;
        Random r;
        public Form1()
        {
            InitializeComponent();
            direction = Direction.RIGHT;
            theta = 0;
            count = 1;
            r = new Random();
        }

        private void sharpTimer_Tick(object sender, EventArgs e)
        {
            dollarLabel.Visible = !dollarLabel.Visible;
            sharpLabel.BackColor = Color.FromArgb(r.Next(0,255),r.Next(0,255),r.Next(0,255));
            if (direction == Direction.RIGHT)
            {
                if (sharpLabel.Right < this.ClientRectangle.Width)
                    sharpLabel.Left += 2;
                else direction = Direction.DOWN;
            }
            else if(direction == Direction.DOWN)
            {
                if (sharpLabel.Bottom < this.ClientRectangle.Height)
                    sharpLabel.Top += 2;
                else direction = Direction.LEFT;
            }
            else if (direction == Direction.LEFT)
            {
                if (sharpLabel.Left > 0)
                    sharpLabel.Left -= 2;
                else direction = Direction.UP;
            }
            else if (direction == Direction.UP)
            {
                if (sharpLabel.Top > 0)
                    sharpLabel.Top -= 2;
                else
                {
                    direction = Direction.RIGHT;
                    sharpTimer.Enabled = false;//sharp stops
                    dollarTimer.Enabled = true;
                }
            }
        }

        private void dollarTimer_Tick(object sender, EventArgs e)
        {
            
            if(theta >= 2* Math.PI * count)
            {
                dollarTimer.Enabled = false;
                sharpTimer.Enabled = true;
                count++;
            }
            theta += 0.1;
            dollarLabel.Left = (int)(100 + 80 * Math.Cos(theta));
            dollarLabel.Top = (int)(100 + 80 * Math.Sin(theta));
            
        }
    }
}
